package thumbnail

import (
	"math"
	"testing"

	"github.com/stretchr/testify/require"
)

func TestDecodePathTo(t *testing.T) {
	testData := []uint8{
		0x1a, 0x00, 0xb2, 0x04, 0xdc, 0x47, 0x03, 0x81, 0x73, 0x55, 0x48, 0x01, 0x46, 0x05, 0x44, 0x45,
		0x4f, 0x8b, 0x52, 0x8d, 0x4e, 0x8a, 0x5d, 0x8b, 0x6e, 0x8b, 0x71, 0x81, 0x4c, 0x4d, 0x07, 0x47,
		0x50, 0x02, 0x81, 0x46, 0x84, 0x4b, 0x83, 0x50, 0x80, 0x44, 0x67, 0x47, 0x01, 0x6b, 0x47, 0x08,
		0x43, 0x44, 0x4f, 0x53, 0x43, 0x56, 0x8e, 0x44, 0x97, 0x94, 0x9d, 0x9c, 0x82, 0x84, 0x89, 0x45,
		0x8b, 0x42, 0x88, 0x8a, 0xa6, 0xb3, 0xa8, 0xbc, 0x81, 0x8a, 0x81, 0xad, 0x82, 0xae, 0x87, 0x88,
		0xa5, 0x67, 0xab, 0x6a, 0x92, 0x49, 0xaa, 0x42, 0xb6, 0x4e, 0x8d, 0x4e, 0x5e, 0x80, 0x69, 0x43,
		0x45, 0x41, 0x4a, 0x46, 0x4d, 0x49, 0x52, 0x51, 0x8a, 0x46, 0x89, 0x47, 0x4b, 0x4f, 0x5f, 0x5b,
		0x6d, 0x67, 0x64, 0x5f, 0x46, 0x06, 0x48, 0x08, 0x63, 0x4d, 0x03, 0xa1, 0x70, 0x89, 0x06, 0x81,
		0x8b, 0x01, 0x48, 0x87, 0x44, 0x8a, 0x4c, 0x91, 0x51, 0x98, 0x51, 0x87, 0x03, 0x81, 0x89, 0x04,
		0x8f, 0x88, 0x86, 0x90, 0x8e, 0x95, 0x97, 0x81, 0x81, 0x82, 0x8b, 0x84, 0x8c, 0x98, 0x8d, 0xb2,
		0x93, 0x87, 0x00, 0xa9, 0xab, 0xad, 0x8e, 0x8a, 0x07, 0x69, 0x8c, 0x05, 0x5a, 0x89, 0x75, 0x84,
		0x48, 0x00, 0x87, 0x46, 0x80, 0x8c, 0x86, 0x92, 0x86, 0x90, 0x81, 0xa4, 0x4b, 0xb2, 0x81, 0x95,
		0x91, 0x9b, 0xab, 0xab, 0xbf, 0x95, 0x99, 0x87, 0x03, 0xb9, 0x87, 0x00, 0x89, 0x04, 0x42, 0xac,
		0x4e, 0x04, 0xb5, 0x51, 0x04, 0xb3, 0x4a, 0x81, 0x46, 0x86, 0x4a, 0x8b, 0x41, 0x81, 0x43, 0x44,
		0x45, 0x43, 0x51, 0x85, 0x5c, 0x8c, 0x6f, 0x8c,
	}
	expected := []uint8{
		0x4d, 0x32, 0x36, 0x30, 0x2c, 0x35, 0x30, 0x34, 0x63, 0x2d, 0x37, 0x33, 0x2c, 0x31, 0x2d, 0x35,
		0x31, 0x2d, 0x32, 0x31, 0x2d, 0x38, 0x31, 0x2d, 0x36, 0x35, 0x2d, 0x34, 0x2d, 0x35, 0x2d, 0x31,
		0x35, 0x2c, 0x31, 0x31, 0x2d, 0x31, 0x38, 0x2c, 0x31, 0x33, 0x2d, 0x31, 0x34, 0x2c, 0x31, 0x30,
		0x2d, 0x32, 0x39, 0x2c, 0x31, 0x31, 0x2d, 0x34, 0x36, 0x2c, 0x31, 0x31, 0x2d, 0x34, 0x39, 0x2c,
		0x31, 0x2d, 0x31, 0x32, 0x2d, 0x31, 0x33, 0x37, 0x2d, 0x37, 0x2d, 0x31, 0x36, 0x32, 0x2c, 0x31,
		0x2d, 0x36, 0x2c, 0x34, 0x2d, 0x31, 0x31, 0x2c, 0x33, 0x2d, 0x31, 0x36, 0x2c, 0x30, 0x2d, 0x34,
		0x2d, 0x33, 0x39, 0x2d, 0x37, 0x31, 0x2d, 0x34, 0x33, 0x2d, 0x37, 0x38, 0x2d, 0x33, 0x2d, 0x34,
		0x2d, 0x31, 0x35, 0x2d, 0x31, 0x39, 0x2d, 0x33, 0x2d, 0x32, 0x32, 0x2c, 0x31, 0x34, 0x2d, 0x34,
		0x2c, 0x32, 0x33, 0x2c, 0x32, 0x30, 0x2c, 0x32, 0x39, 0x2c, 0x32, 0x38, 0x2c, 0x32, 0x2c, 0x34,
		0x2c, 0x39, 0x2d, 0x35, 0x2c, 0x31, 0x31, 0x2d, 0x32, 0x2c, 0x38, 0x2c, 0x31, 0x30, 0x2c, 0x33,
		0x38, 0x2c, 0x35, 0x31, 0x2c, 0x34, 0x30, 0x2c, 0x36, 0x30, 0x2c, 0x31, 0x2c, 0x31, 0x30, 0x2c,
		0x31, 0x2c, 0x34, 0x35, 0x2c, 0x32, 0x2c, 0x34, 0x36, 0x2c, 0x37, 0x2c, 0x38, 0x2c, 0x33, 0x37,
		0x2d, 0x33, 0x39, 0x2c, 0x34, 0x33, 0x2d, 0x34, 0x32, 0x2c, 0x31, 0x38, 0x2d, 0x39, 0x2c, 0x34,
		0x32, 0x2d, 0x32, 0x2c, 0x35, 0x34, 0x2d, 0x31, 0x34, 0x2c, 0x31, 0x33, 0x2d, 0x31, 0x34, 0x2d,
		0x33, 0x30, 0x2c, 0x30, 0x2d, 0x34, 0x31, 0x2d, 0x33, 0x2d, 0x35, 0x2d, 0x31, 0x2d, 0x31, 0x30,
		0x2d, 0x36, 0x2d, 0x31, 0x33, 0x2d, 0x39, 0x2d, 0x31, 0x38, 0x2d, 0x31, 0x37, 0x2c, 0x31, 0x30,
		0x2d, 0x36, 0x2c, 0x39, 0x2d, 0x37, 0x2d, 0x31, 0x31, 0x2d, 0x31, 0x35, 0x2d, 0x33, 0x31, 0x2d,
		0x32, 0x37, 0x2d, 0x34, 0x35, 0x2d, 0x33, 0x39, 0x2d, 0x33, 0x36, 0x2d, 0x33, 0x31, 0x2d, 0x36,
		0x36, 0x2d, 0x38, 0x38, 0x2d, 0x33, 0x35, 0x2d, 0x31, 0x33, 0x33, 0x2c, 0x33, 0x33, 0x2d, 0x34,
		0x38, 0x2c, 0x39, 0x36, 0x2c, 0x31, 0x2c, 0x31, 0x31, 0x31, 0x2d, 0x38, 0x2c, 0x37, 0x2d, 0x34,
		0x2c, 0x31, 0x30, 0x2d, 0x31, 0x32, 0x2c, 0x31, 0x37, 0x2d, 0x31, 0x37, 0x2c, 0x32, 0x34, 0x2d,
		0x31, 0x37, 0x2c, 0x37, 0x33, 0x2c, 0x31, 0x2c, 0x39, 0x34, 0x2c, 0x31, 0x35, 0x2c, 0x38, 0x2c,
		0x36, 0x2c, 0x31, 0x36, 0x2c, 0x31, 0x34, 0x2c, 0x32, 0x31, 0x2c, 0x32, 0x33, 0x2c, 0x31, 0x2c,
		0x31, 0x2c, 0x32, 0x2c, 0x31, 0x31, 0x2c, 0x34, 0x2c, 0x31, 0x32, 0x2c, 0x32, 0x34, 0x2c, 0x31,
		0x33, 0x2c, 0x35, 0x30, 0x2c, 0x31, 0x39, 0x2c, 0x37, 0x30, 0x2c, 0x34, 0x31, 0x2c, 0x34, 0x33,
		0x2c, 0x34, 0x35, 0x2c, 0x31, 0x34, 0x2c, 0x31, 0x30, 0x37, 0x2d, 0x34, 0x31, 0x2c, 0x31, 0x32,
		0x35, 0x2d, 0x32, 0x36, 0x2c, 0x39, 0x2d, 0x35, 0x33, 0x2c, 0x34, 0x2d, 0x38, 0x30, 0x2c, 0x37,
		0x2d, 0x36, 0x2c, 0x30, 0x2c, 0x31, 0x32, 0x2c, 0x36, 0x2c, 0x31, 0x38, 0x2c, 0x36, 0x2c, 0x31,
		0x36, 0x2c, 0x31, 0x2c, 0x33, 0x36, 0x2d, 0x31, 0x31, 0x2c, 0x35, 0x30, 0x2c, 0x31, 0x2c, 0x32,
		0x31, 0x2c, 0x31, 0x37, 0x2c, 0x32, 0x37, 0x2c, 0x34, 0x33, 0x2c, 0x34, 0x33, 0x2c, 0x36, 0x33,
		0x2c, 0x32, 0x31, 0x2c, 0x32, 0x35, 0x2c, 0x37, 0x33, 0x2c, 0x35, 0x37, 0x2c, 0x37, 0x30, 0x2c,
		0x39, 0x34, 0x2d, 0x32, 0x2c, 0x34, 0x34, 0x2d, 0x31, 0x34, 0x34, 0x2c, 0x35, 0x33, 0x2d, 0x31,
		0x37, 0x34, 0x2c, 0x35, 0x31, 0x2d, 0x31, 0x30, 0x2c, 0x31, 0x2d, 0x36, 0x2c, 0x36, 0x2d, 0x31,
		0x30, 0x2c, 0x31, 0x31, 0x2d, 0x31, 0x2c, 0x31, 0x2d, 0x33, 0x2d, 0x34, 0x2d, 0x35, 0x2d, 0x33,
		0x2d, 0x31, 0x37, 0x2c, 0x35, 0x2d, 0x32, 0x38, 0x2c, 0x31, 0x32, 0x2d, 0x34, 0x37, 0x2c, 0x31,
		0x32, 0x7a,
	}

	a := require.New(t)
	r := DecodePath(testData)
	a.Equal(expected, r)

	for i := byte(0); i < math.MaxUint8; i++ {
		DecodePath([]byte{i})
	}
}
